package jp.team.nature.reizoukoapp.dialog;

import jp.team.nature.reizoukoapp.R;
import jp.team.nature.reizoukoapp.ZaikoKakuninActivity;
import jp.team.nature.reizoukoapp.db.ReizoukoItem;
import android.app.Dialog;
import android.app.DialogFragment;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;

public class CustomDialogFragment extends DialogFragment{
	private EditText editText;
	private ReizoukoItem selectedItem;

	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {
		Dialog dialog = new Dialog(getActivity());
	    dialog.setTitle("数量入力");
	    dialog.setContentView(R.layout.dialog);

	    editText = (EditText)(dialog.findViewById(R.id.inputQuantity));

	    dialog.findViewById(R.id.buttonTouroku).setOnClickListener(new OnClickListener() {
	      @Override
	      public void onClick(View v) {

	        String text = editText.getText().toString();
	        ZaikoKakuninActivity callingActivity = (ZaikoKakuninActivity) getActivity();
	        callingActivity.onReturnValue(text, selectedItem);

	        dismiss();
	      }
	    });
	    dialog.findViewById(R.id.buttonAll).setOnClickListener(new OnClickListener() {
		      @Override
		      public void onClick(View v) {

		        String text = "all";
		        ZaikoKakuninActivity callingActivity = (ZaikoKakuninActivity) getActivity();
		        callingActivity.onReturnValue(text, selectedItem);

		        dismiss();
		      }
		    });
	    dialog.findViewById(R.id.buttonCancel).setOnClickListener(new OnClickListener() {
		      @Override
		      public void onClick(View v) {
		        String text = "cancel";
		        ZaikoKakuninActivity callingActivity = (ZaikoKakuninActivity) getActivity();
		        callingActivity.onReturnValue(text, selectedItem);
		        dismiss();
		      }
		    });

	    return dialog;
	}

	public ReizoukoItem getSelectedItem() {
		return selectedItem;
	}

	public void setSelectedItem(ReizoukoItem selectedItem) {
		this.selectedItem = selectedItem;
	}
}
